package com.bangdream.michelia.view.adapter;


import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.text.Html;
import android.view.View;
import android.widget.ImageView;

import com.bangdream.michelia.R;
import com.bangdream.michelia.entity.courses.CoursesBean;
import com.bangdream.michelia.utils.ImageLoadUtils;
import com.bangdream.michelia.utils.StausUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

/**
 * Created by zhouyi on 2018/3/25.
 */

public class CourseListAdapter extends BaseQuickAdapter<CoursesBean,BaseViewHolder> {

    private Drawable selectBg,selectedBg;
    private int selectTextColor,selectedTextColor;

    public CourseListAdapter(int layoutResId) {
        super(layoutResId);
     }

    @Override
    protected void convert(BaseViewHolder helper, CoursesBean bean) {
        selectTextColor =mContext.getResources().getColor(R.color.text_color);
        selectedTextColor = mContext.getResources().getColor(R.color.common_red);
        selectBg = mContext.getResources().getDrawable(R.drawable.cutting_gray_line);
        selectedBg = mContext.getResources().getDrawable(R.drawable.cutting_red_line);

        ImageLoadUtils.ImageLoad(mContext,bean.getFaceUrl(),(ImageView) helper.getView(R.id.ivIcon),-1);
        helper.setText(R.id.tvTitle, bean.getName()+"");
        helper.setText(R.id.tvContent, Html.fromHtml(bean.getIntroduction())+"");
        helper.setText(R.id.tvCollection, bean.getCollectCount()+"");
        helper.setText(R.id.tvZan, bean.getBuyCount()+"");
        helper.setText(R.id.tvPeopleNumber, bean.getCollectCount()+"");


        if(bean.isCollect()){
            helper.getView(R.id.btnCollection).setBackground(selectedBg);
            helper.setTextColor(R.id.tvCollection,selectedTextColor);
            helper.setImageResource(R.id.ivCollection,R.mipmap.icon_collection2);
        }else {
            helper.getView(R.id.btnCollection).setBackground(selectBg);
            helper.setTextColor(R.id.tvCollection,selectTextColor);
            helper.setImageResource(R.id.ivCollection,R.mipmap.icon_collection1);
        }

        if(bean.getLearnStatus()!=null) {
            helper.setVisible(R.id.tvState,true);
            helper.setText(R.id.tvState,StausUtils.coursesStateToText(bean.getLearnStatus()));
        }else {
            helper.setVisible(R.id.tvState,false);
        }

    }
}
